package com.coc.web;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice(basePackages={"com.coc.web", "com.coc.web"})
@ResponseBody
public class ExceptionsHandler {

/*    @ExceptionHandler(Exception.class)//可以直接写@EceptionHandler，IOExeption继承于Exception
    public ModelAndView allExceptionHandler(Exception exception) {
        ModelAndView modelAndView = new ModelAndView("generic_error");
        modelAndView.addObject("errMsg", "this is Exception.class");
        return modelAndView;
    }*/

    @ExceptionHandler(Exception.class)//可以直接写@EceptionHandler，IOExeption继承于Exception
    public Object allExceptionHandler(Exception exception) {
        return exception.getMessage();
    }

    @ExceptionHandler(RuntimeException.class)
    public Object allExceptionHandler(RuntimeException exception) {
        return exception.getMessage();
    }
}
